<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>我的订单</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
    <link href="{$Think.config.RESOURCEURL}wx_assets/quan/orderList.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js{$Think.config.RESOURCE_VER}"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/wx_share.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/product/cookie.js{$Think.config.RESOURCE_VER}"></script>
</head>
<style>
    @font-face {
        font-family: 'iconf';
        src: url('//at.alicdn.com/t/font_1462783003_3582804.eot'); /* IE9*/
        src: url('//at.alicdn.com/t/font_1462783003_3582804.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
        url('//at.alicdn.com/t/font_1462783003_3582804.woff') format('woff'), /* chrome、firefox */
        url('//at.alicdn.com/t/font_1462783003_3582804.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/
        url('//at.alicdn.com/t/font_1462783003_3582804.svg#iconfont') format('svg'); /* iOS 4.1- */
    }
    .iconf
    {
        font-family: 'iconf' !important;
    }
    i{
        font-style: normal;
    }
    .sq-top
    {
        height: 50px;
        padding: 0px 50px;
        background: #ff8f12;
        color: white;
        position: relative;
        z-index: 2;

    }
    .sq-top a.sq-btn-top
    {
        display: block;
        width: 50px;
        height: 50px;
        line-height: 50px;
        text-align: center;
        color: white;
        position: absolute;
        top: 0px;
        font-size: 22px;
        left:0px;
    }
    .sq-top a.sq-btn-top.back-btn
    {
        padding-left: 5px;
        width: 80px;
    }
    .sq-top a.sq-btn-top > span
    {
        font-size: 13px;
    }
    .sq-top .middle
    {
        line-height: 50px;
        text-align: center;
        color: white;
        font-size:20px;
    }
    .searchicon{
        color:#ccc;
        font-size:16px;
        font-family:"iconf";
        float: left;
        line-height: 35px;
        margin-left: 10px;
    }
    .order-box .order-inner .order-info .status >i{
        font-family: 'iconf' !important;
        font-size: 15px;
    }
</style>
<body>
<div class="sq-top">
    <a  class="sq-btn-top" onclick="history.go(-1);"><i class="iconf">&#xe603;</i></a>
    <div class="middle">
        我的订单
    </div>
</div>
<div class="order-search">
    <i class="searchicon">&#xe600;</i>
    <input type="text" id="search" placeholder="输入商品名">
</div>
<div>
    <ul class="order-status">
        <li class="current">组团中</li>
        <li>待发货</li>
        <li>已发货</li>
        <li>已完成</li>
        <li>退款单</li>
    </ul>
</div>
<div class="main" id="orderListBox">
</div>
<script type="text/javascript">
    template.helper('picFormat',function(picUrl1){
        var picUrl = JSON.parse(picUrl1);
        if(picUrl[1]){
            return picUrl[1]['picUrl'];
        }else{
            return picUrl[0]['picUrl'];
        }
    });
</script>
<script type="text/html" id="OrderListTpl">
    <% if(orderList) {
    for(var i=0,len=orderList.length;i<len;i++) {
    var item=orderList[i];
    item.total=item.price+((+item.logisticsCost) || 0);
    %>
    <div class="order-box">
        <div class="order-inner">
            <div class="order-info" onclick="orderList.orderDetail('<%=item.id%>','<%=uType%>')">
                 <span class="orderNumber">订单日期：<%=item.createTime%></span>
                <span class="status"><a>
                    <%if(item.status=='ok'){%>
                    交易成功
                    <%}%>
                    <%if(item.status=='notsubmit'){%>
                    未提交
                    <%}%>
                    <%if(item.status=='closed'){%>
                    交易关闭
                    <%}%>
                    <%if(item.status=='paying'){%>
                    等待付款
                    <%}%>
                    <%if(item.status=='delivering'){%>
                    等待发货
                    <%}%>
                    <%if(item.status=='delivered'){%>
                    已发货
                    <%}%>
                    <%if(item.status=='refund'){%>
                    已退款
                    <%}%>
                    <%if(item.status=='refunding'){%>
                    退款中
                    <%}%>
                    <%if(item.status=='payingconfirm'){%>
                    付款确认中
                    <%}%>
                    <%if(item.status=='teaming'){%>
                    组团中
                    <%}%>
                    <%if(item.status=='paypart'){%>
                    部分付款
                    <%}%>
                    <%if(item.status=='partake'){%>
                    已参与夺宝
                    <%}%>
                    <%if(item.status=='deliveringtostore'){%>
                    等待配送到自提点
                    <%}%>
                    <%if(item.status=='deliveredtostore'){%>
                    已配送到自提点
                    <%}%>
                    <%if(item.status=='ordersign'){%>
                    已报名
                    <%}%>
                    <%if(item.status=='confirmsign'){%>
                    已确认报名
                    <%}%>
                    <%if(item.status=='canclesign'){%>
                    已取消报名
                    <%}%>
                    <%if(item.status=='supported'){%>
                    众筹中
                    <%}%>
                </a>
                <i class="iconf">&#xe602;</i>
                </span>
            </div>
            <% if(item.productList) {
            for(var j=0;j<item.productList.length;j++) {
            var p=item.productList[j];
            %>
            <dl class="pro-list"  onclick="orderList.toDetail('<%=p.fromCustomerId%>','<%=p.pid%>','<%=item.qId%>','<%=p.sId%>')">
                <dt>
                    <%if(p.picUrl1&&p.picUrl1!='[]'){%>
                    <img src="<%=picFormat(p.picUrl1)%>" onload="$.util.imgCenter(this)"/>
                    <%}else{%>
                    <img src="<%=p.picUrl%>" onload="$.util.imgCenter(this)"/>
                    <%}%>
                </dt>
                <dd>
                    <div class="name">
                        <a><%=p.name%></a>
                    </div>
                    <div class="price">
                        售价：<span>￥<%=p.price%></span>
                            <span>
                                <%if(uType==1){%>
                                    <%if(item.miUid==uId){%>
                                    (￥<%=p.miAward%>)
                                    <%}else if(item.refereeUid==uId){%>
                                    (￥<%=p.refereeAward%>)
                                    <%}else{%>
                                     (￥<%=p.parentRefereeAward%>)
                                    <%}%>
                                <%}else{%>
                                    (￥<%=p.lordAward%>)
                                <%}%>
                            </span>
                        <br/>
                        <span>&nbsp;</span>
                    </div>
                </dd>
            </dl>
            <%}%>
            <%}%>
        </div>
    </div>
    <%}%>
    <%} else {%>
    <div class="norecord">
        <div class="norecord-div">
            <i class="iconf" style="font-size: 75px;color:#ccc;margin-bottom:30px;display: block;">&#xe601;</i>
            <span style="color:#FF8F12">你还没有订单</span>
            <span style="color:#9D9C9B">快快把宝贝推广出去吧</span>
        </div>
    </div>
    <%}%>
</script>
<script type="text/javascript">
    var baseUrl = '{$Think.config.SERVER_HOST}';
    var orderList={
        pageSize:10,
        page:0,
        append:false,
        init:function(){
            var me=this;
            this._initEvent();
            $.util.pageLoading.show();
            var orderstatus = getCookie("order-status");
            if(orderstatus){
                $(".order-status li:eq("+orderstatus+")").addClass("current").siblings().removeClass("current");
                me._loadList(me.page,function(){
                    $.util.pageLoading.hide();
                    var orderscroll = getCookie("orderscroll");
                    if(orderscroll){
                        document.body.scrollTop=orderscroll;
                    }
                });
            }else{
                me._loadList(me.page,function(){
                    $.util.pageLoading.hide();
                    var orderscroll = getCookie("order-scroll");
                    if(orderscroll){
                        document.body.scrollTop=orderscroll;
                    }
                });
            }
        },
        _initEvent:function(){
            var me=this;
            $.util.initDataLoading({
                me:orderList,
                lastChildren:function(){
                    return $("#orderListBox .order-box:last");
                },
                page:function(){
                    return orderList.page;
                },
                pageCount:function(){
                    return orderList.pageCount;
                }
            });
            $(".order-status li").click(function(){
                $(this).addClass("current").siblings().removeClass("current");
                $("#dataEnd").remove();
//                $("#orderListBox").empty();
                orderList.append = true;
                setCookie('order-status',$(this).index());
                $.util.pageLoading.show();
                orderList.pageSize=10;
                orderList.page=0;
                me._loadList(me.page,function(){
                    $.util.pageLoading.hide();
                    orderList.append = false;
                });
            });
            $("#search").keypress(function(e){
                switch(e.which)
                {
                    case 13:
                        orderList.append = true;
                        orderList.page=0;
                        $.util.pageLoading.show();
                        me._loadList(me.page,function(){
                            $.util.pageLoading.hide();
                            orderList.append = false;
                        });
                        break;
                }
            }).blur(function(){
                if($(this).val()){
                    orderList.append = true;
                    orderList.page=0;
                    $.util.pageLoading.show();
                    me._loadList(me.page,function(){
                        $.util.pageLoading.hide();
                        orderList.append = false;
                    });
                }
            });
        },
        _renderList:function(data,page,callback){
            var me=this;
            if(data){
                var html=template("OrderListTpl", data),
                        container=$("#orderListBox");
                if(orderList.append){
                    container.html(html);
                }else{
                    container.append(html);
                }
                me.page=page;
                me.pageCount=data.pageCount;
                callback && callback();
            }
        },
        _loadList:function(page,callback){
            var p=$.util.getParamAsObject();
            var me=this;
            var identity = p.identity?2:1;
            var status = $(".order-status .current").index();
            var search = $("#search").val().trim();
            $.req.get("call.json?module=quan&customerId={$customerId}&method=getOrderList",{
                userName:"{$userName}",
                params:{
                    "qId":"{$qId}",
                    "type":identity,
                    "status":status,
                    "search":search,
                    "start":page,
                    "limit":me.pageSize
                }
            },function(data){
                if(data){
                    me._renderList(data,page,callback);
                }
            });
        },
        orderDetail:function(oid,utype){
            var p={
                oid:oid,
                uType:utype
            };
            p=encodeURIComponent(JSON.stringify(p));
            var scrollTop =  document.body.scrollTop;
            setCookie("orderscroll",scrollTop);
            var detailUrl=baseUrl+'call.html?customerId={$customerId}&module=quan&method=getOrderDetail&params='+p;
            location.href=detailUrl;
        },
        toDetail:function(formCustomerId,pId,qId){
            var p={
                qId:qId,
                id:pId
            };
            p=encodeURIComponent(JSON.stringify(p));
            var scrollTop =  document.body.scrollTop;
            setCookie("orderscroll",scrollTop);
            var detailUrl=baseUrl+'call.html?customerId='+formCustomerId+'&module=product&method=getProduct&params='+p;
            location.href=detailUrl;
        }
    }

    orderList.init();
    wx_share.init({
        "pkg":{
            "appId": '{$pkg.appId}',
            "timestamp": '{$pkg.timestamp}',
            "nonceStr": '{$pkg.nonceStr}',
            "signature": '{$pkg.signature}'
        },
        hide:1
    });
</script>
</body>
</html>